#include "BodyFactory.h"

#include "AABBTree.h"
#include "ComplexBodyShape.h"
#include "SphereBodyShape.h"
#include "CubeBodyShape.h"
#include "BoxBodyShape.h"
#include "pw_exception.h"

namespace physicsworks {

using exception::IBadArg;

RigidBody* BodyFactory::instanceRigidBody(vec3* vertices, int numVertices, const int* verticesIndices, int numFaces)
{
	Assert<IBadArg>(numVertices > 2, "The numVertices must be greater than 2");
	Assert<IBadArg>(numFaces > 0, "The numFaces must be greater than 0");
	
	// change this...
	return new RigidBody(new ComplexBodyShape<AABBTree>(vertices, numVertices, verticesIndices, numFaces));
}

RigidBody* BodyFactory::instanceSphere(real radius)
{
	Assert<IBadArg>(math::greater<real>(radius, 0), "The radius must be greater than 0 (epsilon)");
	
	return new RigidBody(new SphereBodyShape(radius));
}

RigidBody* BodyFactory::instanceCube(real radius)
{
	Assert<IBadArg>(math::greater<real>(radius, 0), "The radius must be greater than 0 (epsilon)");
	
	return new RigidBody(new CubeBodyShape(radius));
}

RigidBody* BodyFactory::instanceBox(vec3 radius)
{
	using math::greater;
	Assert<IBadArg>(greater<real>(radius.x, 0) && greater<real>(radius.y, 0) &&
	                greater<real>(radius.z, 0), "The radius must has the values of x, y, and z greater than 0 (epsilon)");
	
	return new RigidBody(new BoxBodyShape(radius));
}

}
